package mybatis.interceptor.example.mapper;

import mybatis.interceptor.example.entity.UserInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author guan.xin
 * @title UserInfoDao
 * @description
 * @create 2022-04-21 12:08
 * @since JDK8
 */
public interface UserInfoDao {

    @Select("SELECT user_id, user_name, real_name, nick_name, user_type FROM user_info WHERE id IN (1, 2, 3)")
    @Result(property = "userId", column = "user_id", jdbcType = JdbcType.VARCHAR)
    @Result(property = "userName", column = "user_name", jdbcType = JdbcType.VARCHAR)
    @Result(property = "realName", column = "real_name", jdbcType = JdbcType.VARCHAR)
    @Result(property = "nickName", column = "nick_name", jdbcType = JdbcType.VARCHAR)
    @Result(property = "userType", column = "user_type", jdbcType = JdbcType.CHAR)
    List<UserInfo> getAll();

    @Select("SELECT user_id, user_name, real_name, nick_name, user_type FROM user_info WHERE id = #{id}")
    @Result(property = "userId", column = "user_id", jdbcType = JdbcType.VARCHAR)
    @Result(property = "userName", column = "user_name", jdbcType = JdbcType.VARCHAR)
    @Result(property = "realName", column = "real_name", jdbcType = JdbcType.VARCHAR)
    @Result(property = "nickName", column = "nick_name", jdbcType = JdbcType.VARCHAR)
    @Result(property = "userType", column = "user_type", jdbcType = JdbcType.CHAR)
    UserInfo getOne(Long id);

    @Insert("INSERT INTO user_info(user_id, user_name, real_name, nick_name, user_type) VALUES(#{userId}, #{userName}, #{realName}, #{nickName}, #{userType})")
    void insert(UserInfo userInfo);

    @Update("UPDATE user_info SET user_id = #{userId}, user_name = #{userName}, user_name = #{userName}, real_name = #{realName}, nick_name = #{nickName}, user_type = #{userType} WHERE id = #{id}")
    void update(UserInfo userInfo);

    @Delete("DELETE FROM user_info WHERE id = #{id}")
    void delete(Long id);

}
